<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 求一个数字是否是质数?
        function demo(num){
           var shu = true;
           for (var i = 2; i<num ; i++){    /*除了1和自己之外,不能被其它数整除*/
               if (num % i === 0){
                    shu = false;            /*能够整除就标记为 false*/
                    break;                  /*不再循坏*/
               }
           }
           return shu;
        }

        var result = demo(+prompt("请输入数字"));
        if (result){
            console.log("是质数");
            document.write("是质数");         
        }else{
            console.log( "不是质数");
            
        }
     
    </script>
</body>
</html>